<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>千园千变，万班万课</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>
<body data-type="generalComponents">
<div class="tpl-portlet-components">
    <div class="portlet-title">
        <ol class="am-breadcrumb">
            <li><a href="#" class="am-icon-home">首页</a></li>
            <li><a href="#">Amaze UI CSS</a></li>
            <li class="am-active">文字列表</li>
        </ol>
        <button class="refresh_btn"><i class="am-icon-refresh"></i></button>
    </div>
    <div class="tpl-block">
        <div class="am-g">
            <div class="am-u-sm-12 am-u-md-2">
                <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <button type="button" class="am-btn am-btn-default am-btn-success btn_add"><span
                                class="am-icon-plus"></span> 新增
                        </button>
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-7">
                <div class="am-form-group line">
                    <select class="am-form-field" id="province" name="province_id"
                            style="width: 150px;margin-right: 10px">
                        <option value="0">请选择省</option>
                    </select>
                    <select class="am-form-field" id="city" name="city_id"
                            style="width: 150px;margin-right: 10px">
                        <option value="0">请选择市</option>
                    </select>
                    <select class="am-form-field" id="county" name="country_id" style="width: 150px">
                        <option value="0">请选择区县</option>
                    </select>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-3">
                <div class="am-input-group am-input-group-sm">
                    <input type="text" id="search" class="am-form-field">
                    <span class="am-input-group-btn">
                        <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
                                type="button" id="searchBtn"></button>
                    </span>
                </div>
            </div>
        </div>
        <div class="am-g">
            <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main" id="table">
                    <thead>
                    <tr>
                        <th class="table-id" width="120">ID</th>
                        <th class="table-title" width="120">姓名</th>
                        <th class="table-type">名称</th>
                        <th class="table-author ">机构名称</th>
                        <th class="table-author">服务码</th>
                        <th class="table-date ">地区</th>
                        <th class="table-date">登录时间</th>
                        <th class="table-set" width="220">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
                <div class="am-cf">
                    <div class="am-fr">
                        <div class="am-pagination tpl-pagination" id="pagination"></div>
                    </div>
                </div>
                <hr>
            </div>
        </div>
    </div>
</div>
<div class="am-g tpl-amazeui-form model_panel" id="editPasswordPanel" style="display: none">
    <div class="am-u-sm-12">
        <form class="am-form am-form-horizontal">
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label">账号</label>
                <div class="am-u-sm-9 line">
                    <b id="userName" class="am-form-label"></b>
                </div>
            </div>
            <div class="am-form-group">
                <label for="pwd" class="am-u-sm-3 am-form-label">密码</label>
                <div class="am-u-sm-9">
                    <input type="password" id="one_pwd" name="one_pwd" style="width: 300px" placeholder="输入密码">
                </div>
            </div>
            <div class="am-form-group">
                <label for="two_pwd" class="am-u-sm-3 am-form-label">确认密码</label>
                <div class="am-u-sm-9">
                    <input type="password" id="two_pwd" name="two_pwd" style="width: 300px"
                           placeholder="输入确认密码">
                </div>
            </div>
        </form>
    </div>
</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/layer.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/md5.min.js"></script>
<script src="assets/js/jquery.pagination.js"></script>
<script src="assets/js/jquery.serializejson.min.js"></script>
<script src="assets/js/request.js"></script>
<script src="assets/js/verification.js"></script>
<script src="assets/js/app.js"></script>
</body>
<script>
//获取地址
function getArea (id, elem, callback) {
  AjaxRequest({
    url: '/admin/city_list/',
    data: {id},
    succFun: function (res) {
      var data = res.data
      var html = '<option value="0">请选择省</option>'
      data.forEach(function (d) {
        html += ' <option value="' + d.id + '">' + d.fullName + '</option>'
      })
      $(elem).html(html)
      callback && callback()
    }
  })
}
getArea('0', '#province')
$('#province').change(function () {
  var id = $(this).val()
  getArea(id, '#city')
  $('#county').val('0')
})
$('#city').change(function () {
  var id = $(this).val()
  getArea(id, '#county')
})
var page = '1'
var size = '10'
var search = ''
var province_id = ''
var country_id = ''
var city_id = ''
var total = 0
function getDataList (callback) {
  AjaxRequest({
    url: '/admin/agent_list/',
    data: {page, size, search, province_id, country_id, city_id},
    succFun: function (res) {
      var data = res.data
      total = data.count
      var html = ''
      res.data.list.forEach(function (d, i) {
        html += ` <tr>
                    <td>${d.admin_id}</td>
                    <td><a href="#">${d.username}</a></td>
                    <td>${d.name}</td>
                    <td>${d.institution_name || '--'}</td>
                    <td>${d.serve_code}</td>
                    <td>${d.city_name}</td>
                    <td>${d.login_time || '--'}</td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <button class="am-btn am-btn-success am-btn-xs btn_edit" data-id="${d.admin_id}"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                <button class="am-btn am-btn-secondary am-btn-xs btn_edit_password"  data-id="${d.admin_id}" data-username="${d.username}">修改密码</button>
                                <button class="am-btn am-btn-default am-btn-xs am-text-danger btn_delete"  data-id="${d.admin_id}" ><span class="am-icon-trash-o"></span> 删除</button>
                            </div>
                        </div>
                    </td>
                </tr>`
      })
      $('#table tbody').html(html)
      callback && callback()
    }
  })
}
function init () {
  getDataList(function () {
    $('#pagination').pagination({
      pageCount: Math.ceil(total / size),
      jump: true,
      coping: true,
      keepShowPN: true,
      prevContent: '«',
      nextContent: '»',
      jumpBtnCls: 'am-btn am-btn-primary',
      activeCls: 'am-active',
      callback: function (api) {
        console.log(api.getCurrent())
        page = api.getCurrent().toString()
        getDataList()
      }
    });
  })
}
init()
//删除
$('table').on('click', '.btn_delete', function () {
  let admin_id = $(this).attr('data-id')
  layer.confirm('确认要删除该条记录吗？', {
    btn: ['确定', '取消'] //按钮
  }, function () {
    AjaxRequest({
      url: '/admin/admin_del/',
      data: {admin_id},
      succFun: function (res) {
        layer.msg(res.message, {icon: 1})
        getDataList()
      }
    })
  });
})
//修改或新增
$('body').on('click', '.btn_edit,.btn_add', function (e) {
  e.preventDefault()
  let id = $(this).attr('data-id')
  location.href = 'admin_update_or_add.html?id=' + id
})
//搜索
$('#searchBtn').click(function (e) {
  e.preventDefault()
  search = $('#search').val().toString()
  province_id = $('#province').val().toString()
  city_id = $('#city').val().toString()
  country_id = $('#county').val().toString()
  page = '1'
  init()
})
//修改密码
$('body').on('click', '.btn_edit_password', function (e) {
  e.preventDefault()
  let admin_id = $(this).attr('data-id')
  let userName = $(this).attr('data-username')
  $('#userName').html(userName)
  layer.open({
    type: 1,
    title: '修改密码',
    area: ['500px', '280px'],
    shadeClose: true, //点击遮罩关闭
    btn: ['确定', '取消'],
    content: $('#editPasswordPanel'),
    yes: function () {
      if (Verification()) {
        var formData = $('#editPasswordPanel form').serializeJSON()
        formData.admin_id = admin_id
        AjaxRequest({
          url: '/admin/pwd_admin/',
          data: formData,
          succFun: function (res) {
            layer.msg(res.message, {icon: 1, time: 1500}, function () {
              layer.closeAll()
            })
          }
        })
      }

    }
  });
})
</script>
</html>